<template>
	<div class="aid">
		<div class="base">
			<p class="fixed-top">
				{{ JSON.stringify(text) == '{}' ? '添加获奖记录' : '修改获奖记录' }}
				<a-icon @click="closeFunction" type="close" />
			</p>
			<div class="main" id="new_message">
				<a-form-model ref="ruleForm" :model="form" :rules="rules">
					<a-form-model-item label="获奖成员" prop="ActivityMemberID">
						<a-select v-model="form.ActivityMemberID" showSearch optionFilterProp="children" style="width:100%" >
							<a-select-option v-for="(item, index) in userList" :key="index" :value="item.ID">{{item.UserNo}} - {{ item.Name }}</a-select-option>
						</a-select>
					</a-form-model-item>
					<a-form-model-item label="奖项" prop="ActivityTypePrizeID">
						<a-select v-model="form.ActivityTypePrizeID" showSearch optionFilterProp="children" style="width:100%" >
							<a-select-option v-for="(item, index) in ActivityTypePrizeList" :key="index" :value="item.ID">{{ item.Title }}</a-select-option>
						</a-select>
					</a-form-model-item>
					<a-form-model-item label="" class="fixed-bottom">
						<a-button type="primary" @click="handleSubmit">{{ JSON.stringify(text) == '{}' ? '确认添加' : '确认修改' }}</a-button>
						<a-button style="margin-left: 10px;" @click="closeFunction">取消</a-button>
					</a-form-model-item>
				</a-form-model>
			</div>
		</div>
	</div>
</template>

<script>
import { UserDoAddActivityMemberPrize,UpdateActivityTypePrize } from '@/api/follow';
export default {
	props: {
		text: Object,
		userList:Array,
		ActivityTypePrizeList:Array
	},
	watch: {
		text: function(text) {
			this.currentID = text.ID
			if (!this.currentID) {
			} else {
				this.form = text;
			}
		}
	},
	data() {
		return {
			formLayout: 'horizontal',
			form: this.$form.createForm(this, {
				name: 'coordinated'
			}),
			currentID:'',
			DepartmenDropdowntList: [],
			form: {
				ActivityMemberID: '',
				ActivityTypePrizeID:'',
			},
			rules: {
				ActivityMemberID: [
					{
						required: true,
						message: '请选择成员',
						trigger: 'change'
					}
				],
				ActivityTypePrizeID: [
					{
						required: true,
						message: '请选择奖项',
						trigger: 'change'
					}
				],
			}
		};
	},
	methods: {
		closeFunction(data) {
			this.$emit('closeFun', data);
			this.form = {};
		},
		handleSubmit(e) {
			this.$refs.ruleForm.validate(async valid => {
				if (valid) {
					let data = this.form;
					data.ActivityTypeID = this.$route.query.activityTypeID
					let res = {}
					if (JSON.stringify(this.text) == '{}') {
						res = await UserDoAddActivityMemberPrize(data);
					} else {
						res = await UpdateActivityTypePrize(data);
					}
					if (res.data.code === 0) {
						this.$message.error(res.data.msg);
						// let data=res.data.data;
						// let str=''
						// for(let i=0;i<data.length;i++){
						// 	if(!data[i].IsSuccess){
						// 		str=str+data[i].UserNo+data[i].Msg+';'
						// 	}
						// }
						// this.$message.error(str);
						this.closeFunction('1');
					}else{
						this.$message.error(res.data.msg);
					}
				} else {
					return false;
				}
			});
		}
	}
};
</script>

<style lang="less" scoped>
	/deep/.ant-form-item {
		margin: 20px 50px;
		display: flex;
	}
	/deep/.ant-form-item-label {
		width: 100px;
		overflow: hidden;
		white-space: nowrap;
		text-overflow: ellipsis;
		text-align: right;
	}
	/deep/.ant-form-item-control-wrapper {
		flex: 1;
	}

.ant-form-item {
	margin-bottom: 10px;
}

.btn2 {
	display: -moz-box;
	-moz-box-pack: center;
	-moz-box-align: center;

	/* Safari、Opera 以及 Chrome */
	display: -webkit-box;
	-webkit-box-pack: center;
	-webkit-box-align: center;

	/* W3C */
	display: flex;
	box-pack: center;
	box-align: center;
	width: 137px;
	height: 35px;
	border-radius: 3px;
	outline: none;
	border: none;
	margin: 20px auto;
	color: #fff;
}
.fixed-top {
	width: inherit;
	position: absolute;
	line-height: 30px;
	top: 0px;
	background-color: white;
	z-index: 999;
}
/deep/.ant-form {
	margin-top: 50px;
	padding-bottom: 50px;
}
</style>
